#pragma once

#include "effectbase.h"
#include <osg/NodeCallback>
#include <osg\Timer>
#include <osg\PositionAttitudeTransform>

namespace VrDataCore
{
	class SwingAnimationEffect;

	class SwingAnimationEffectUpdateCallback : public osg::NodeCallback
	{
	public:
		SwingAnimationEffectUpdateCallback(SwingAnimationEffect* un);
		~SwingAnimationEffectUpdateCallback(){} ;
		virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
	protected:
		SwingAnimationEffect*				_un ;
	};

	class VRDATACORE_EXPORT SwingAnimationEffect:public EffectBase
	{
	public:
		SwingAnimationEffect(int swing = false);
	protected:
		~SwingAnimationEffect();
	public:
		void setMaxDistance(osg::Vec3 dis);
		osg::Vec3 getMaxDistance();
		void setAnimationTime(float time);
		float getAnimationTime();
		void update();
		void startToEnd();
		void endToStart();
		virtual void onMapLoadBegin(CoreBase::Map*){}
		virtual void onMapLoadEnd(CoreBase::Map*){}
		virtual void reset(){}
		virtual void apply(CoreBase::ActorBase* actor);
		virtual void unApply(CoreBase::ActorBase* actor);
	private:
		float						_totalTime;
		osg::Timer_t				_startTick;
		bool						_update;
		osg::ref_ptr<SwingAnimationEffectUpdateCallback>	_updateCallback;
		bool						_setupCallback;
		osg::Vec3					_maxDistance;
		bool						_startToEnd;
		osg::ref_ptr<osg::PositionAttitudeTransform>		_transform;
	};
}